package api

import (
	"os"
	"fmt"
	"kumachan/interpreter/runtime/debug"
	"kumachan/interpreter/runtime/rt"
)

func __DebugLog(v rt.Value, k rt.Value, h rt.InteropContext) rt.Value {
	const bold = "\033[1m"
	const reset = "\033[0m"
	var repr = debug.InspectUntypedValue(v)
	var loc, ok = h.Location()
	if ok {
		var loc = loc.SourceLocation()
		fmt.Fprintf (
			os.Stderr, "--- %vdebug-log:%v %s at %s\n%s\n",
			bold, reset, loc.PosDesc(), loc.FilePath(), repr,
		)
	} else {
		fmt.Fprintf (
			os.Stderr, "--- %vdebug-log:%v top-level\n%s\n",
			bold, reset, repr,
		)
	}
	return h.Call(k, nil)
}


